<extend name="Public:mainbase"/>
<block name="content">
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-switch.min.css">
    <script src="__PUBLIC__/js/bootstrap-switch.min.js" type="text/javascript"></script>


    <div class="panel panel-default">
        <div class="panel-body">
            <table width="98%" class="table table-bordered  table-hover table-condensed " align="center">
                <tr bgcolor="#E7E7E7">
                    <td colspan="7" height="28" background="__PUBLIC__/images/tbg.gif" style="padding-left:10px;">
                        ◆ 系统配置（双击选项修改）
                    </td>
                </tr>

                <tr align="center" bgcolor="#FBFCE2" height="25">
                    <td width="5%"></td>
                    <td width="20%">配置选项</td>
                    <td width="10%">key</td>
                    <td width="10%">字符类型</td>
                    <td width="35%">数值</td>
                    <td width="10%">修改时间</td>
                    <td width="10%"></td>
                </tr>

                <volist name="systemconfig" id="vo">
                <tr height="34" align="center" bgcolor="#FFFFFF" height="26" data-id="{$vo.id}" class="dataTable">
                    <td><input type="checkbox" class="id" value="{$vo.id}" aria-label="{$vo.id}"></td>
                    <td class="canEdit" data-key="name">{$vo.name}</td>
                    <td class="canEdit" data-key="config">{$vo.config}</td>
                    <td class="canEdit" data-key="type">{$vo.type}</td>
                    <td class="canEdit" data-key="value">{$vo.value}</td>
                    <td>{$vo.insert_time|date="Y-m-d H:i",###}</td>

                    <td>
                        <button type="button" class="btn btn-xs btn-warning delConfig"><i class="glyphicon glyphicon-remove"></i>  删除</button>
                    </td>
                </tr>
                </volist>
                <tr>
                    <td height="36"  colspan="7">
                        <button type="button" class="btn btn-xs btn-danger" data-toggle="modal" data-target=".key"><i class="glyphicon glyphicon-plus"></i>  添加配置</button>
                        <button type="button" class="btn btn-xs btn-warning delAllConfig"><i class="glyphicon glyphicon-remove"></i>  删除配置</button>
                    </td>
                </tr>

                <tr align="left" bgcolor="#F9FCEF" style="font-size: 16px">
                    <td height="36" colspan="7">
                        当前配置文件版本：<span class="label label-info">{$systemconfigver.ver}</span> ，生成时间： <span class="label label-info">{$systemconfigver.insert_time|date="Y-m-d H:i:s",###}</span>
                    </td>
                </tr>

                <tfoot>

                </tfoot>
            </table>

        </div>
    </div>


    <div class="modal fade key" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content" style="padding:15px">
                <form class="form-horizontal" method="post" action="postAddConfig">
                    <div class="form-group">
                        <label for="name" class="col-xs-4 control-label">提示内容</label>
                        <div class="col-xs-7">
                            <input type="text" class="form-control" id="name" name="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="config" class="col-xs-4 control-label">字段名</label>
                        <div class="col-xs-7">
                            <input type="text" class="form-control" id="config" name="config" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="type" class="col-xs-4 control-label">字符类型</label>
                        <div class="col-xs-7">
                            <select class="form-control" name="type" id="type">
                                <option value=""> </option>
                                <option value="string">字符串</option>
                                <option value="int">整数</option>
                                <option value="tinyint">布尔</option>
                                <option>浮点</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="value" class="col-xs-4 control-label">值</label>
                        <div class="col-xs-7">
                            <input type="text" class="form-control" id="value" name="value" >
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-xs-offset-4 col-xs-10">
                            <button type="submit" class="btn btn-info">确定添加</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="__PUBLIC__/js/jquery.focusEnd.js"></script>

    <script type="text/javascript">
        $("tfoot").load("{:U('makeNewConfigBTN')}");
        $(".dataTable .canEdit").dblclick(function(){
            var _this=this;
            var orgData=$(_this).text();
            $(_this).html('<input class="form-control editInput input-sm" data-orgdata="'+orgData+'" value="'+orgData+'" />');
            $(".dataTable .editInput").focusEnd();
        });


        $(".dataTable").on("blur",'.editInput',function(){
            var _this=this;
            var act=false;
            if($(_this).data('orgdata')!=$(_this).val()){
                if(confirm('是否确定修改此选项？')){
                    var data={};
                    data['id']=$(_this).parent().parent().data('id');
                    data[$(_this).parent().data('key')]=$(_this).val();
                    $.ajax({
                        async:false,
                        cache:false,
                        type:'post',
                        data:data,
                        url:'{:U("ajaxEditConfig")}',
                        success:function(data2){
                            if(data2.status==1){
                                $("tfoot").load("{:U('makeNewConfigBTN')}");
                                $(_this).parent().html($(_this).val());
                                act=true;
                            }else{
                                alert(data2.info);
                            }
                        }
                    })
                }
            }

            if(!act){
                $(".dataTable .editInput").parent().html($(".dataTable .editInput").data('orgdata'))
            }

        });

        $(".delConfig").click(function(){
            var _this=this;
            if(confirm('是否确定删除此选项？')){
                var data={};
                data['id']=$(_this).parent().parent().data('id');
                $.ajax({
                    async:false,
                    cache:false,
                    type:'post',
                    data:data,
                    url:'{:U("ajaxDelConfig")}',
                    success:function(data2){
                        if(data2.status==1){
                            $("tfoot").load("{:U('makeNewConfigBTN')}");
                            $(_this).parents('tr').remove();
                        }else{
                            alert(data2.info);
                        }
                    }
                })
            }
        })


        $(".delAllConfig").click(function(){
            var _this=this;
            if(confirm('是否确定删除此选项？')){
                var data={};
                data['id']=$(".id:checked").map(function(){
                    return $(this).val();
                }).get().join();



                $.ajax({
                    async:false,
                    cache:false,
                    type:'post',
                    data:data,
                    url:'{:U("ajaxDelConfig")}',
                    success:function(data2){
                        if(data2.status==1){
                            $("tfoot").load("{:U('makeNewConfigBTN')}");
                            $(".id:checked").parents('tr').remove();
                        }else{
                            alert(data2.info);
                        }
                    }
                })
            }
        })


    </script>

</block>